import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/login-ajax")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String result="未知错误";
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        //非空检验
        if(null!=username&&null!=password&&!username.equals("")&&!password.equals("")){
            if(username.equals("admin")&&password.equals("admin")){
                result="登陆成功";
            }else{
                result="用户名和密码输入错误，请重新输入";
            }
        }else{
            result="非法参数";
        }
        //结果返回前段
        resp.setContentType("text/html; charset=utf-8");
        resp.getWriter().write(result);
    }
}
